
<!--客户评级管理-->
<template>
	<div>
		<!--查询部分-->
		<el-row>
			<el-col :span="1">
				<p class="queryLabel">编号名称：</p>
			</el-col>
			<el-col :span="3" style="padding-left: 10px;">
				<el-input v-model="queryData.numberName" size="small" placeholder="请输入编号"></el-input>
			</el-col>
			<el-col :span="1" style="padding-left: 10px;">
				<el-button size="small" type="primary" @click="queryButton">查 询</el-button>
			</el-col>
			<el-col :span="1" style="margin-left: 200px;">
				<el-button size="small" type="primary" @click="addButton">新 增</el-button>
			</el-col>
			<el-col :span="1" style="padding-left: 10px;">
				<el-button size="small" type="primary" @click="editButton">编 辑</el-button>
			</el-col>
			<el-col :span="1" style="padding-left: 10px;">
				<el-button size="small" type="primary" @click="startButton">启 用</el-button>
			</el-col>
			<el-col :span="1" style="padding-left: 10px;">
				<el-button size="small" type="primary" @click="stopButton">停 用</el-button>
			</el-col>
		</el-row>

		<!--表格部分-->
		<el-row>
			<el-col :span="24">
				<el-table :data="tableData.dataList" stripe border @selection-change="handleSelectionChange">
					<el-table-column type="selection" width="50" fixed>
					</el-table-column>
					<el-table-column prop="levelCode" label="等级编号" width="220"></el-table-column>
					<el-table-column prop="levelName" label="等级名称" width="220"></el-table-column>
					<el-table-column label="评级类型" width="220" :formatter="scoreTypeCov"></el-table-column>
					<el-table-column label="评级项" width="220" :formatter="scoreItemCov"></el-table-column>
					<el-table-column prop="start" label="评级值" width="220"></el-table-column>
					<el-table-column prop="stop" label="百分比" width="220"></el-table-column>
					<el-table-column label="状态" width="220" :formatter="statusCov"></el-table-column>
				</el-table>
				<el-pagination small @size-change="handleSizeChange" @current-change="handleCurrentChange" @current-page="CurentPage" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout="total,prev, pager, next" :total="tableData.total"></el-pagination>
			</el-col>
		</el-row>

		<el-dialog title="新增" v-model="addDialogShow" size="tiny">

			<el-form :model="editData" :rules="rules" ref="editData" label-width="100px" class="demo-ruleForm">
				<el-form-item label="选择等级">
					<el-select size="small" v-model="editData.levelCode" placeholder="请选择">
						<el-option v-for="item in levelCodeListCombo" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="评级类型" prop="scoreType">
					<el-select size="small" v-model="editData.scoreType" placeholder="请选择">
						<el-option v-for="item in scoreTypeCombo" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
				</el-form-item>
				<el-row v-if='editData.scoreType == 2 '>
					<el-form-item label="评分项" prop="scoreItem">
						<el-col :span="15">
							<el-select size="small" v-model="editData.scoreItem" placeholder="请选择">
								<el-option v-for="item in scoreItemCombo" :label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</el-col>
					</el-form-item>
				</el-row>

				<el-form-item label="评级值" required>
					<el-col :span="15">
						<el-form-item prop="start">
							<el-input v-model="editData.start" type="number" :min="0" size="small" placeholder="起始值"></el-input>
						</el-form-item>
					</el-col>
				</el-form-item>
				<el-form-item label="百分比" required>
					<el-col :span="15">
						<el-form-item prop="stop">
							<el-input v-model="editData.stop" type="number" :min="0" :max="100" size="small" placeholder="百分比"></el-input>
						</el-form-item>
					</el-col>
				</el-form-item>
			</el-form>

			<el-row>
				<el-col :span="12">
					<el-button type="primary" size="small" style="margin-left: 100px;" @click="addSubmit()">提 交</el-button>
				</el-col>
				<el-col :span="12">
					<el-button type="primary" size="small" style="margin-left: 70px;" @click="addCansel">取 消</el-button>
				</el-col>
			</el-row>
		</el-dialog>
		<div style="color:red;"> 备注：评级类型为得分时，每个等级对应该等级的最小分值，则大于该分值的车辆认定为该等级，评级类型为项目时，每个等级对应的分值为该等级，取相等</div>
	</div>
</template>

<script>
export default {
	data: function() {
		return {
			// 规则
			rules: {
				levelCode: [
					{ required: true, message: '请输入等级编号', trigger: 'blur' }

				],
				scoreType: [
					{ required: true, message: '请输入等级类别', trigger: 'blur' }

				],
				scoreItem: [
					{ required: true, message: '请输入评分项', trigger: 'blur' }

				],




			},
			// 评级类型下拉
			scoreTypeCombo: [{
				label: "得分",
				value: "1",
			}, {
				label: "项目",
				value: "2",
			}],
			// 评分项下拉
			scoreItemCombo: [],
			scoreItemConv: {},
			// 评级方式
			countTypeCombo: [
				{
					label: "升序",
					value: "",
				},
				{
					label: "其它",
					value: "qt",
				}],
			// 等级下拉框
			levelCodeListCombo: [],
			// 新增dialog显示
			addDialogShow: false,
			//  编辑dialog 显示
			editDialogShow: false,
			// 查询集合
			queryData: {
				numberName: "",
			},
			CurentPage: 1,
			page: this.page,
			// 查询数据
			tableData: {
				total: 0,
				dataList: [],
			},
			// 修改数据
			editData: {
				scoreType: "", // 评级类型
				levelCode: "", // 等级代码
				countType: "", // 评分方式
				start: "", // 评级开始值
				stop: "", // 评级结束值
				scoreItem: "", // 评分项
				id: "",
				status: "1",
				dispOrder: "",

			},
			// 修改数据初始化
			emptyEditData: {
				scoreType: "", // 评级类型
				levelCode: "", // 等级代码
				countType: "", // 评分方式
				start: "", // 评级开始值
				stop: "", // 评级结束值
				scoreItem: "", // 评分项
				id: "",
				status: "",
				dispOrder: "",

			},
			// 选择数据
			multipleSelection: "",
			//页码数
			CurentPage: 1,
			//每页的数量
			page: this.page,
		}
	},
	methods: {
		//选择框
		handleSelectionChange: function(val) {
			debugger;
			this.$data.multipleSelection = val;
			/*if(this.$data.multipleSelection.length > 1)
				this.$message.error("请选择一条数据！");*/
		},
		// 查 询
		queryButton: function() {
			//alert("查询");
			debugger;
			this.$http.get(this.API_ROOT + '/bc/custome/level/conf/page', {
				params: {

					levelCode: this.$data.queryData.numberName,
					start: this.$data.CurentPage,
					limit: this.$data.page.pageSize,
				}
			}).then(resp => {
				if (resp.data.success) {
					resp.data.total = parseInt(resp.data.total);
					this.$data.tableData.dataList = resp.data.dataList;
					this.$data.tableData.total = resp.data.total;
				} else {
					this.$message.error(resp.data.msg);
				}
			}, resp => {
			});
		},
		// 添加按钮
		addButton: function() {
			//alert("新增");
			debugger;
			this.$data.editData = Object.assign(this.$data.editData, this.$data.emptyEditData);

			this.$data.addDialogShow = true;
		},

		/**编辑按钮**/
		editButton: function() {
			this.$data.editData = Object.assign(this.$data.editData, this.$data.emptyEditData);
			if (this.$data.multipleSelection.length != 1) {
				this.$message.error("请选择一条数据");
				return;
			}
			this.$http.get(this.API_ROOT + '/bc/custome/level/conf/info', {
				params: {
					id: this.$data.multipleSelection[0].id,
				}
			}).then(resp => {

				if (resp.data.success) {
					this.$data.editData = Object.assign(this.$data.editData, resp.data.data);
				} else {
					//this.$message.error(resp.data.msg);
				}
			}, resp => {
			});
			//alert("编辑");
			this.$data.addDialogShow = true;
		},
		// 启用
		startButton: function() {
			//alert("启用");
			if (this.$data.multipleSelection.length != 1) {
				this.$message.error("请选择一条数据");
				return;
			}
			this.$http.get(this.API_ROOT + '/bc/custome/level/conf/start', {
				params: {
					id: this.$data.multipleSelection[0].id,
				}
			}).then(resp => {
				if (resp.data.success) {
					this.$message(resp.data.msg);
					this.queryButton(); // 刷新
					this.$data.multipleSelection = []; // 选择置空
				} else {
					this.$message.error(resp.data.msg);
					this.queryButton(); // 刷新
					this.$data.multipleSelection = []; // 选择置空
				}
			}, resp => {
			});
		},
		// 停用
		stopButton: function() {
			//alert("停用");
			if (this.$data.multipleSelection.length != 1) {
				this.$message.error("请选择一条数据");
				return;
			}
			this.$http.get(this.API_ROOT + '/bc/custome/level/conf/stop', {
				params: {
					id: this.$data.multipleSelection[0].id,
				}
			}).then(resp => {
				if (resp.data.success) {
					this.$message(resp.data.msg);
					this.queryButton(); // 刷新
					this.$data.multipleSelection = []; // 选择置空
				} else {
					this.$message.error(resp.data.msg);
					this.queryButton(); // 刷新
					this.$data.multipleSelection = []; // 选择置空
				}
			}, resp => {
			});
		},
		/**【添加】提交**/
		addSubmit: function() {
			//alert("新增提交");
			this.$refs["editData"].validate((valid) => {
				if (valid) {
					if (this.$data.editData.scoreType == 1) {
						this.$data.editData.scoreItem = "";
					}
					debugger;
					this.$http.post(this.API_ROOT + '/bc/custome/level/conf/save', this.$data.editData, {
						params: {
						}
					}).then(resp => {
						if (resp.data.success) {
							//resp.data.total = parseInt(resp.data.total);
							//this.$data.tableData.dataList = resp.data.dataList;
							//this.$data.tableData.total = resp.data.total;
							this.$data.addDialogShow = false;
							this.$message("保存成功！");
							this.queryButton();
						} else {
							this.$message.error(resp.data.msg);
						}
					}, resp => {
					});

				} else {
					this.$message.error("表单填写不全！");
					return false;
				}
			});

		},
		/**【添加】取消**/
		addCansel: function() {
			//alert("新增取消");
			this.$data.addDialogShow = false;
		},

		/** 【编辑】提交 **/
		editSubmit: function(formName) {
			//alert("新增提交");
			debugger;
			this.$refs[formName].validate((valid) => {
				if (valid) {
					if (this.$data.editData.scoreType == 1) {
						this.$data.editData.scoreItem = "";
					}
					//this.$data.editData.id = this.$data.multipleSelection[0].id;
					debugger;
					this.$http.post(this.API_ROOT + '/bc/custome/level/conf/save', this.$data.editData, {
						params: {
						}
					}).then(resp => {
						if (resp.data.success) {
							//resp.data.total = parseInt(resp.data.total);
							//this.$data.tableData.dataList = resp.data.dataList;
							//this.$data.tableData.total = resp.data.total;
							this.$data.addDialogShow = false;
							this.$message("保存成功！");
							this.queryButton();
						} else {
							this.$message.error(resp.data.msg);
						}
					}, resp => {
					});

				} else {
					this.$message.error("表单填写不全！");
					return false;
				}
			});

		},
		/**【编辑】 取消**/
		editCansel: function() {
			//alert("新增取消");
			this.$data.addDialogShow = false;
		},

		//列表分页大小切换
		handleSizeChange: function() { },
		//列表当前页切换
		handleCurrentChange: function(currentPage) {
			this.$data.CurentPage = currentPage;
			this.queryButton();
		},
		// 状态转换
		statusCov: function(row) {
			switch (row.status) {
				case '1':
					return "已启用";
					break;
				default:
					return "未启用";
					break;

			}
		},

		levelCombo: function() {

			this.$http.get(this.API_ROOT + '/bc/custome/level/combo', {
				params: {

				}
			}).then(resp => {
				debugger;
				this.$data.levelCodeListCombo = resp.data;
			}, resp => {
			});
		},


		// 评级类型转换
		scoreTypeCov: function(row) {
			switch (row.scoreType) {
				case "1":
					return "得分";
					break;
				case "2":
					return "项目";
					break;
				default:
					return "未知";
					break;
			}

		},

		scoreItemCov: function(row) {
			return this.$data.scoreItemConv[row.scoreItem];
		}
	},
	created: function() {
		this.levelCombo();
		this.queryButton();

		this.$http.get(this.API_ROOT + '/bc/custome/item/combo', {
			params: {

			}
		}).then(resp => {
			debugger;
			this.$data.scoreItemCombo = resp.data;
		}, resp => {
		});

		this.$http.get(this.API_ROOT + '/bc/custome/item/convert', {
			params: {

			}
		}).then(resp => {
			debugger;
			this.$data.scoreItemConv = resp.data;
		}, resp => {
		});
	}
}
</script>

<style>

</style>